Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tracing): Favour client options tracePropagationTargets #8399

Merged
merged 2 commits into from
Jun 27, 2023

Conversation

AbhiPrasad
Copy link
Member

@AbhiPrasad AbhiPrasad commented Jun 23, 2023

ref #8352

As we work toward adding tracing without performance support, this PR updates the BrowserTracing integration to use and favour the top level tracePropagationTargets option if it exists.

This option was made top level in #8395

tracePropagationTargets is now part of the unified API for distributed tracing. It's also expected that electron/react native will behave the same way as well. This also leaves us the flexibility to extract tracing out of BrowserTracing, or create a new integration that just does tracing but no performance monitoring.

We can make sure this migration is smooth and easy to understand with a good set of docs, which is what I will be working on next. In these docs changes, we'll be updating the automatic instrumentation sections, and formally documented tracePropagationTargets as a high level option.

@AbhiPrasad AbhiPrasad requested review from a team, mydea and lforst and removed request for a team June 23, 2023 17:10
@github-actions
Copy link
Contributor

github-actions bot commented Jun 23, 2023

size-limit report 📦

Path Size
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 21.3 KB (+0.01% 🔺)
@sentry/browser - ES5 CDN Bundle (minified) 66.43 KB (0%)
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 19.82 KB (0%)
@sentry/browser - ES6 CDN Bundle (minified) 58.9 KB (0%)
@sentry/browser - Webpack (gzipped + minified) 21.43 KB (0%)
@sentry/browser - Webpack (minified) 69.87 KB (0%)
@sentry/react - Webpack (gzipped + minified) 21.46 KB (0%)
@sentry/nextjs Client - Webpack (gzipped + minified) 49.51 KB (+0.26% 🔺)
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 28.91 KB (+0.1% 🔺)
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 27.15 KB (+0.13% 🔺)
@sentry/replay ES6 CDN Bundle (gzipped + minified) 49.34 KB (0%)
@sentry/replay - Webpack (gzipped + minified) 43.1 KB (0%)
@sentry/browser + @sentry/tracing + @sentry/replay - ES6 CDN Bundle (gzipped + minified) 68.51 KB (+0.06% 🔺)
@sentry/browser + @sentry/replay - ES6 CDN Bundle (gzipped + minified) 61.38 KB (-0.01% 🔽)

shouldCreateSpanForRequest,
_experiments,
} = this.options;

const tracePropagationTargets =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, does it make sense that the top-level options take precedence? 🤔 I think I would expect the options that are passed directly to the integration to "win", so:

this.options.tracePropagationTargets || (clientOptions && clientOptions.tracePropagationTargets);

? Not a big thing, as I don't expect this to happen too often, though :) So feel free to ignore.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's a fair perspective actually. Let's discuss this at our meeting.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on our meeting we've made two decisions.

  1. We'll be combining the arrays of both top level and integration set tracePropagationTargets
  2. We'll be emitting a warning when both values are set.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Detailed below I decided against the combining array approach, but added the warning in b098188

@AbhiPrasad
Copy link
Member Author

I experimented with merging in two arrays - but found it would be confusing to users because of the deprecated tracingOrigins. Since we now have three different configs, I figured having one supercede the others is the easiest way to explain behaviour, and we can document this everywhere as well.

Here's a git patch with the logic I was testing with

diff --git a/packages/tracing-internal/src/browser/browsertracing.ts b/packages/tracing-internal/src/browser/browsertracing.ts
index 202f4fe7a..755aae6a3 100644
--- a/packages/tracing-internal/src/browser/browsertracing.ts
+++ b/packages/tracing-internal/src/browser/browsertracing.ts
@@ -177,9 +177,15 @@ export class BrowserTracing implements Integration {
 
   private _collectWebVitals: () => void;
 
+  // See `tracePropagationTargets` in `setupOnce` for why this is commented out.
+  // private _hasSetTracePropagationTargets: boolean = false;
+
   public constructor(_options?: Partial<BrowserTracingOptions>) {
     addTracingExtensions();
 
+    // eslint-disable-next-line deprecation/deprecation
+    // this._hasSetTracePropagationTargets = !!(_options && (_options.tracePropagationTargets || _options.tracingOrigins));
+
     this.options = {
       ...DEFAULT_BROWSER_TRACING_OPTIONS,
       ..._options,
@@ -229,8 +235,23 @@ export class BrowserTracing implements Integration {
       _experiments,
     } = this.options;
 
-    const tracePropagationTargets =
-      (clientOptions && clientOptions.tracePropagationTargets) || this.options.tracePropagationTargets;
+    const clientOptionsTracePropagationTargets = clientOptions && clientOptions.tracePropagationTargets;
+    // There are three ways to configure tracePropagationTargets:
+    // 1. via top level client option `tracePropagationTargets`
+    // 2. via BrowserTracing option `tracePropagationTargets`
+    // 3. via BrowserTracing option `tracingOrigins` (deprecated)
+    //
+    // To avoid confusion, favour top level client option `tracePropagationTargets`, and fallback to
+    // BrowserTracing option `tracePropagationTargets` and then `tracingOrigins` (deprecated).
+    // This is done as it minimizes bundle size (we don't have to have undefined checks).
+    //
+    // If both 1 and either one of 2 or 3 are set (from above), we log out a warning.
+    const tracePropagationTargets = clientOptionsTracePropagationTargets || this.options.tracePropagationTargets;
+    // This warning will be in a future release after 7.57.0 when we formally deprecated the
+    // BrowserTracing`tracePropagationTargets` option.
+    // if (__DEBUG_BUILD__ && this._hasSetTracePropagationTargets && clientOptionsTracePropagationTargets) {
+    //   logger.warn('[Tracing] You have set options for tracePropagationTargets in BrowserTracing and top level `Sentry.init`. The SDK is defaulting to use value for top level `tracePropagationTargets` in client.');
+    // }
 
     instrumentRouting(
       (context: TransactionContext) => {

I'm only going to be adding a warning as a result.

@AbhiPrasad AbhiPrasad requested a review from mydea June 26, 2023 17:22
@AbhiPrasad AbhiPrasad merged commit ac435dd into develop Jun 27, 2023
@AbhiPrasad AbhiPrasad deleted the abhi-browser-tracing-propagation branch June 27, 2023 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants